/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EdicionDatosAnimal.java
 *
 * Created on 14-12-2010, 02:07:22 AM
 */
package vista;

import conexionBaseDatos.InsertInputData;
import javax.swing.JOptionPane;

/**
 *
 * @author David Vallejos A
 */
public class EdicionDatosAnimal extends javax.swing.JFrame {

    private String rutTrabajo = "";

    /** Creates new form EdicionDatosAnimal */
    public EdicionDatosAnimal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel8 = new javax.swing.JPanel();
        jLabel23 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        CajaNombreMascEdita = new javax.swing.JTextField();
        jLabel48 = new javax.swing.JLabel();
        jLabel58 = new javax.swing.JLabel();
        cajaRazaMascEdita = new javax.swing.JTextField();
        cajaEdadMascEdita = new javax.swing.JTextField();
        selectorTipoEdadMascEdita = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        selectorTipoAnimalEdita = new javax.swing.JComboBox();
        botonAceptarEdiciónAnimal = new javax.swing.JButton();
        BotonCancelarEdicionAnimal = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Edicion Datos Paciente");

        jPanel8.setBackground(new java.awt.Color(255, 255, 255));

        jLabel23.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel23.setText("Datos Paciente");

        jLabel27.setText("Nombre:");

        jLabel48.setText("Raza:");

        jLabel58.setText("Edad:");

        selectorTipoEdadMascEdita.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MESES", "AÑOS" }));

        jLabel1.setText("Tipo animal:");

        selectorTipoAnimalEdita.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MASCOTA", "GRANJA" }));

        botonAceptarEdiciónAnimal.setText("aceptar");
        botonAceptarEdiciónAnimal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarEdiciónAnimalActionPerformed(evt);
            }
        });

        BotonCancelarEdicionAnimal.setText("volver");
        BotonCancelarEdicionAnimal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonCancelarEdicionAnimalActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGap(114, 114, 114)
                .addComponent(jLabel23)
                .addContainerGap(106, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel27)
                            .addComponent(jLabel48)
                            .addComponent(jLabel58))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel8Layout.createSequentialGroup()
                                .addComponent(cajaEdadMascEdita, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(selectorTipoEdadMascEdita, 0, 126, Short.MAX_VALUE))
                            .addComponent(CajaNombreMascEdita, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                            .addComponent(cajaRazaMascEdita, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel8Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(selectorTipoAnimalEdita, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(30, 30, 30))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                .addContainerGap(138, Short.MAX_VALUE)
                .addComponent(botonAceptarEdiciónAnimal)
                .addGap(18, 18, 18)
                .addComponent(BotonCancelarEdicionAnimal)
                .addGap(34, 34, 34))
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel23)
                .addGap(32, 32, 32)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel27)
                    .addComponent(CajaNombreMascEdita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel48)
                    .addComponent(cajaRazaMascEdita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel58)
                    .addComponent(cajaEdadMascEdita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(selectorTipoEdadMascEdita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(selectorTipoAnimalEdita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BotonCancelarEdicionAnimal)
                    .addComponent(botonAceptarEdiciónAnimal))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BotonCancelarEdicionAnimalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonCancelarEdicionAnimalActionPerformed

        VentanaPrincipal volver = new VentanaPrincipal();
        this.dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_BotonCancelarEdicionAnimalActionPerformed

    private void botonAceptarEdiciónAnimalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarEdiciónAnimalActionPerformed

        this.actualizaDatosPaciente();
        // TODO add your handling code here:
    }//GEN-LAST:event_botonAceptarEdiciónAnimalActionPerformed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonCancelarEdicionAnimal;
    private javax.swing.JTextField CajaNombreMascEdita;
    private javax.swing.JButton botonAceptarEdiciónAnimal;
    private javax.swing.JTextField cajaEdadMascEdita;
    private javax.swing.JTextField cajaRazaMascEdita;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel58;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JComboBox selectorTipoAnimalEdita;
    private javax.swing.JComboBox selectorTipoEdadMascEdita;
    // End of variables declaration//GEN-END:variables

    void obtieneRut(String rut) {
        this.rutTrabajo = rut;
    }

    public String getRutTrabajo() {
        return rutTrabajo;
    }

    private void actualizaDatosPaciente() {

        String rutBD = getRutTrabajo();

        //datos de la mascota
        String nombreMasc = CajaNombreMascEdita.getText().toUpperCase();
        String razaMasc = cajaRazaMascEdita.getText().toUpperCase();
        int edad = Integer.parseInt(cajaEdadMascEdita.getText());
        String tipoEdad = (String) selectorTipoEdadMascEdita.getSelectedItem();
        String tipoAnimal = (String) selectorTipoAnimalEdita.getSelectedItem();

        InsertInputData.actualizarDatosPaciente(rutBD, nombreMasc, edad, tipoEdad);
        InsertInputData.actualizarDatosRaza(rutBD, razaMasc);
        InsertInputData.actualizarDatosTipoAnimal(rutBD, tipoAnimal);

        JOptionPane.showMessageDialog(null, "DATOS INGRESADOS CORRECTAMENTE");

        VentanaPrincipal volver = new VentanaPrincipal();
        this.dispose();
    }
}
